<?php

class Licencia extends DBAbstractModel {
    
     public $grado;
     public $lugar_expedida;
     public $fecha;
     public $vence;
     public $personas_cedula;
     
     function save() {
        $this->query = '';
        $this->query = "INSERT INTO licencias (grado,lugar_expedida,fecha,vence,personas_cedula) VALUES ";
        $this->query.="('$this->grado','$this->lugar_expedida',";
        if ($this->fecha == "NULL") {
            $this->query.=" $this->fecha',";
        } else if ($this->fecha != "NULL") {
            $this->query.=" '$this->fecha',";
        } if ($this->vence == "NULL") {
            $this->query.=" $this->vence','$this->personas_cedula')";
        } else if ($this->vence != "NULL") {
            $this->query.=" '$this->vence','$this->personas_cedula')";
        } 
        
        echo "query insertar: " . $this->query . "</br>";
        $this->execute_single_query();
    }
     function delete($key) {
 
        $this->query = '';
        $this->query = "DELETE FROM licencias WHERE personas_cedula='$key'";
        echo "query eliminar: " . $this->query . "</br>";
        $this->execute_single_query();
    }
    
    
     function update($key) {
        $this->query = '';
        $this->query = "UPDATE licencias SET personas_cedula='$this->personas_cedula',";
        $this->query.=" grado='$this->grado', lugar_expedida='$this->lugar_expedida',";
        if ($this->fecha == "NULL") {
            $this->query.=" fecha=$this->fecha',";
        } else if ($this->fecha != "NULL") {
            $this->query.=" fecha='$this->fecha',";
        } if ($this->vence == "NULL") {
            $this->query.=" vence=$this->vence' WHERE  personas_cedula='$key'";;
        } else if ($this->vence != "NULL") {
            $this->query.=" vence='$this->vence' WHERE  personas_cedula='$key'";;
        }
        echo "query actualizar: " . $this->query . "</br>";
        $this->execute_single_query();
        }
        
    function get($key) {
        if ($key != ''):
            $this->query = "SELECT *FROM licencias WHERE personas_cedula = '$key'";
            $this->get_results_from_query();
        endif;
    }
    function getAll() {
        $this->query = "SELECT *FROM licencias";
        $this->get_results_from_query();
    }
     
}
?>

